from __future__ import division
import os

print "I think this will go well"

inputFileName = "/data1/team/obukai/machine-learning-project-related/learningToPrune/qrels.tb04-tb06.top150_CONTAINS_ONLY_147"
inputFileHandler = open(inputFileName,"r")

outputFileName = "/data1/team/obukai/machine-learning-project-related/trec-related/trecCombine04_06/priorityTrecDocumentsIDs_all_sorted_with_index_number.txt"
outputFileHandler = open(outputFileName,"w")

trecDocumentsIDsRelatedList = []
trecDocumentsIDsRelatedOutputList = []
# trecDocumentsIDsRelatedTuple

for index,line in enumerate( inputFileHandler.readlines() ):
    print "index:",index
    lineElements = line.strip().split(" ")
    
    queryIDUnused = lineElements[0]
    unknownInfoUnused = lineElements[1]
    trecIDUsed = lineElements[2]
    relevenceScoreUsed = lineElements[3]
    if trecIDUsed not in trecDocumentsIDsRelatedList:
        trecDocumentsIDsRelatedList.append(trecIDUsed)
        # record only the first relevenceScoreUsed
        trecDocumentsIDsRelatedOutputList.append( (trecIDUsed,relevenceScoreUsed) )
    else:
        pass

    # print lineElements

print "len(trecDocumentsIDsRelatedOutputList):",len(trecDocumentsIDsRelatedOutputList)

# Let's output the meta file
trecDocumentsIDsRelatedList.sort(cmp=None, key=None, reverse=False)
trecDocumentsIDsRelatedOutputList.sort(cmp=None, key=None, reverse=False)

for index,tuple in enumerate( trecDocumentsIDsRelatedOutputList ):
    ( trecIDUsed,relevenceScoreUsed ) = tuple
    outputFileHandler.write(str(index) + " " + trecIDUsed + " " + relevenceScoreUsed + "\n")



inputFileHandler.close()
outputFileHandler.close()



